<template>
	<view :class="config.style">
		<!-- #ifdef H5-->
		<Top :config="config"></Top>
		<!-- #endif -->
		<!--数据列表部分-->
		<view class="list-section uni-clearfix">
			<!-- top="xxx"下拉布局往下偏移,防止被悬浮菜单遮住 -->
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" :top="msecrollTop" :down="downOption" @down="downCallback" @up="upCallback">
				<!-- 数据列表 -->
				<view class="list">
					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="avatar">
							<image :src="item.user_info.avatar" mode="widthFix"></image>
						</view>
						<view class="info">
							<view class="nickname">
								{{item.user_info.nickname}}
							</view>
							<view class="star">
								<EvaluateStar />
							</view>
							<view class="images" v-if="item.images.length > 0">
								<view v-for="(images_item,images_index) in item.images" :key="images_index" class="image">
									<image @click="preview(index,item.images)" :src="images_item.thumb"></image>
								</view>
							</view>
							<view class="content">
								{{item.content}}
							</view>
							<view class="time">
								{{item.create_time_str}}
							</view>
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import EvaluateStar from '../../../components/muu-evaluate-star/muu-evaluate-star.vue'
	import Top from '../common/top.vue'
	
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			EvaluateStar,
			Top
		},
		data() {
			return {
				urlParams: {}, //url传递过来的参数
				page: 1, //当前页码
				list: [], //列表数据
				msecrollTop: 0,
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption:{
					// page: {
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				},
			}
		},
		onLoad(option) {
			//获取url参数
			this.getUrlParam()
			// #ifdef H5
			this.msecrollTop = 78;
			// #endif
		},
		created() {
			
		},
		computed: {
			...mapState(['config'])
		},
		methods: {

			//获取url参数
			getUrlParam: function(){
				// #ifdef MP-WEIXIN
				console.log('小程序端执行')
				let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
				let curRoute = routes[routes.length - 1].route //获取当前页面路由
				let curParam = routes[routes.length - 1].options; //获取路由参数
				// #endif
			
				// #ifdef H5
				let curParam = this.$route.query;
				// #endif
				this.urlParams = curParam
				console.log(curParam)
			},
			
			//上拉加载的回调
			upCallback: function() {
				let that = this
				let data = this.urlParams
					data.action = 'lists'
					data.page = this.page
				//获取数据
				let url = ''
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/evaluate'
					//#endif
					//#ifdef H5
					url = 'entry/site/evaluate'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							let list = res.data.data.data
							that.list = that.list.concat(list);
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(list.length);
							that.page = that.page + 1
						}
					}
				})
			},
			//下拉刷新
			downCallback: function() {
				let that = this
				this.page = 1
				let data = this.urlParams
					data.action = 'lists'
					data.page = this.page
				//获取数据
				let url = ''
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/evaluate'
					//#endif
					//#ifdef H5
					url = 'entry/site/evaluate'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							that.list = []
							that.list = res.data.data.data
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(that.list.length);
							that.page = 2
						}
					}
				})
			},
			
			//预览
			preview: function(index, urls) {
				//console.log(index)
				//console.log(urls)
				let image_arr = []
				urls.forEach(function(item,index){
					console.log(item)
					image_arr.push(item.preview)
				})
				uni.previewImage({
					urls: image_arr,
					current: index,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
			
		}
	}
</script>

<style lang="scss">
	.list-section {
		.list {
			padding: 20rpx;
			.item {
				display: flex;
				border-bottom: 2rpx solid #f2f2f2;
				padding: 0 0 10rpx 0;
				margin-bottom: 10rpx;
				.avatar {
					width: 96rpx;
					height: 96rpx;
					border-radius: 50%;
					overflow: hidden;
					image {
						width: 96rpx;
						height: 96rpx;
					}
				}
				.info {
					padding-left: 20rpx;
					color: #666;
					.nickname {
						font-size: 24rpx;
						color: 24rpx;
					}
					.star {
						margin: 10rpx 0;
					}
					.images {
						display: flex;
						.image {
							position: relative;
							width: 120rpx;
							height: 120rpx;
							margin: 0 20rpx 20rpx 0;
							border-radius: 10rpx;
							overflow: hidden;
							z-index: 2;
							image {
								width: 120rpx;
								height: 120rpx;
							}
						}
					}
					.content {
						font-size: 24rpx;
						color: 24rpx;
					}
					.time {
						font-size: 24rpx;
						color: 24rpx;
						color: #999;
					}
				}
				&:last-child {
					margin-bottom: 0;
					border-bottom: 0;
					padding-bottom: 0;
				}
			}
		}
	}
	
</style>
